const parser = {
  parseTopics(topics) {
    let lessonsObj = {}
    const testingTypeMap = {
      "0": "未知",
      "1": "常考",
      "2": "必考"
    }
    for (let i = 0, len = topics.length; i < len; i++) {
      let topic = topics[i];
      let lessonId = topic.lessonId;
      if (!lessonsObj[lessonId]) {
        lessonsObj[lessonId] = {
          id: lessonId,
          name: topic.lessonName,
          number: topic.lessonNumber,
          topics: []
        }
      }
      topic.name = topic.content;
      topic.index = i;
      topic.testingText = testingTypeMap[topic.testingType];
      lessonsObj[lessonId].topics.push(topic)
    }
    let lessons = [];
    for (let key in lessonsObj) {
      lessons.push(lessonsObj[key]);
    }
    return lessons;
  },
  parseUnits(units) {
    let unitsArr = [];
    for (let i = 0, len = units.length; i < len; i++) {
      let unitObj = units[i];
      unitObj.children = unitObj.lessons;
      unitObj.lessons = [];
      unitsArr.push(unitObj)
    }
    return units;
  }
}
module.exports = parser;